using OpenTK;

namespace ColladaDotNet.OpenTKMapping
{
	public class IntSource : Source
	{
		private int_array array;
		private accessor accessor;
		internal override void Load(source colladaData)
		{
			base.Load(colladaData);

			array = (int_array)colladaData.Item;
			accessor = colladaData.technique_common.accessor;
		}

		public override ulong Count
		{
			get
			{
				return array.count;
			}
		}

		public override Matrix4d GetMatrix4d(ulong i)
		{
			throw new System.NotImplementedException();
		}

		public override double GetDouble(ulong i)
		{
			i *= accessor.stride;
			return (double)array.Text[i];
		}

		public override string GetString(ulong i)
		{
			i *= accessor.stride;
			return array.Text[i].ToString(DoubleArrayConverter.FormatProvider);
		}

		public override Vector4 GetVector4(ulong i)
		{
			var res = new Vector4(0, 0, 0, 1);
			i *= accessor.stride;
			if (accessor.stride >= 1)
				res.X = (float)array.Text[i];
			if (accessor.stride >= 2)
				res.Y = (float)array.Text[i];
			if (accessor.stride >= 3)
				res.Z = (float)array.Text[i];
			if (accessor.stride >= 4)
				res.W = (float)array.Text[i];
			return res;
		}

		public override Vector3 GetVector3(ulong i)
		{
			var res = new Vector3(0, 0, 0);
			i *= accessor.stride;
			if (accessor.stride >= 1)
				res.X = (float)array.Text[i];
			if (accessor.stride >= 2)
				res.Y = (float)array.Text[i];
			if (accessor.stride >= 3)
				res.Z = (float)array.Text[i];
			return res;
		}
	}
}